local require = require
local uu     = require("modules.commhm.utils")
local auth   = require("modules.business_common.business_auth")
local config = require("modules.business_common.business_config")
local http   = require("modules.business_common.utils.business_http")

local ngx = ngx
local curr = os.time

local table = table
local pairs = pairs
local ipairs = ipairs
local tonumber = tonumber

local FOO = {
    _VERSION = '0.0.1'
}

local http_request = function(uri, data)
    local body = uu.table2json(data)
    local request = {
        cmd     = data.cmd,
        des_uin = data.des_uin,
    }

	local headers = { 
		["Content-Type"]	= "application/json",
		["Authorization"]	= "Basic " .. ngx.encode_base64("minilogic:minipushlogic123")
	}

    local response = uu.json2table(http.Post(uri, request, body, headers) or '')
    if response and tonumber(response.code) == 0 then
        return true, response.data or {}
    end

    -- 失败日志
    http.Log(uu.to_str({ server = uri, request = request, response = response }))
    return false
end

FOO.to_client_refresh_item_notify = function (uin, items_list)
    local uri = config.get_push_send_server_url()
    uin = uin or ngx.ctx.m_params.uin
    return http_request(uri, {
        cmd     = "refresh_item_notify",
        des_uin = uin,
        items_list = items_list
    })
end

return FOO